﻿using BDShop.Configuration;
using BDShop.Entities;
using BDShop.Framework;
using BDShop.Framework.Caching;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BDShop.Business.Cache
{
    public class CategoryCache:BaseCache<List<Category>>
    {
        public CategoryCache()
            : base(BDShopConfiguration.Cache.CacheCategory, CategoryService.GetListCategoryCacheModel, true, CacheManager.GetFilePathFO(CacheEnum.category))
        {
            
        }

        public static CategoryCache Instance
        {
            get
            {
                return SingletonBase<CategoryCache>.Instance;
            }
        }

        private static List<Category> lstCategory;
        public static List<Category> GetList(int catID)
        {
            lstCategory=new List<Category>();
            Category cat =Instance.Get().Where(c => c.ID == catID).Single();
            lstCategory.Add(cat);
            if(cat.ParentID!=0)
            {
                GetList(cat.ParentID);
            }

            return lstCategory;
        }

        public static List<Category> GetParent(int catParentID)
        {
            return Instance.Get().Where(c => c.ParentID == catParentID).ToList();
        }

        public static Category GetByID(int catID)
        {
            return Instance.Get().Where(c => c.ID == catID).Single();
        }
    }
}
